package org.leumasjaffe.initiativeTracker.event;


import java.awt.event.ActionEvent;

import javax.swing.Action;

import org.leumasjaffe.initiativeTracker.Constants;

import org.leumasjaffe.util.io.PortableScanner;
import edu.wpi.heineman.xml.Message;
import edu.wpi.heineman.client.ServerAccess;

@SuppressWarnings("serial")
public class CharGenAction extends InitiativeTrackerAction implements Action {
	
	public CharGenAction(String text) {
		super(text);
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {		
		String xmlString = Message.requestHeader() + "<newRequest game='" + Constants.id + "'>";
		
		xmlString += root.startup().serialize();
		while (true) {
			System.out.print("Make another Character? Y/N: ");
			String s = PortableScanner.nextLine();
			if (s.equalsIgnoreCase("Y") || s.equalsIgnoreCase("Yes"))
				xmlString += root.startup().serialize();
			else 
				break;
		}
		
		xmlString += "</newRequest></request>";
		ServerAccess.getInstance().sendRequest(new Message(xmlString));

		gui.repage();
		gui.repaint();
		System.out.println("End of Character Generation\n");
	}

}

